package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.HotShopClassifyModel;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

/**
 * Created by asus on 2017/5/13.
 */
public class HotShopClassifyLeftAdapter extends RecyclerArrayAdapter<HotShopClassifyModel> {
    private static final int SELECT_TYPE = 0;
    private static final int NORMAL_TYPE = 1;
    private int selectPosition ;

    public HotShopClassifyLeftAdapter(Context context,int selectPosition) {
        super(context);
        this.selectPosition=selectPosition;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == SELECT_TYPE) {
            return new HotShopClassifyLeftSelectedHolder(parent);
        } else if (viewType == NORMAL_TYPE) {
            return new HotShopClassifyLeftHolder(parent);
        }
        return null;

    }
    @Override
    public int getViewType(int position) {

        if (selectPosition==position) {
            return SELECT_TYPE;
        } else {
            return NORMAL_TYPE;
        }

    }

    @Override
    public void OnBindViewHolder(BaseViewHolder holder, int position) {
        super.OnBindViewHolder(holder, position);
    }


    class HotShopClassifyLeftHolder extends BaseViewHolder<HotShopClassifyModel> {
        private TextView tvClassify;

        public HotShopClassifyLeftHolder(ViewGroup parent) {
            super(parent, R.layout.item_classify_left);
            tvClassify = $(R.id.tv_classify_item);
        }

        @Override
        public void setData(HotShopClassifyModel model) {
            super.setData(model);
            tvClassify.setText(model.getCategoryName());
        }
    }
    class HotShopClassifyLeftSelectedHolder extends BaseViewHolder<HotShopClassifyModel> {
        private TextView tvClassify;

        public HotShopClassifyLeftSelectedHolder(ViewGroup parent) {
            super(parent, R.layout.item_classify_left_selected);
            tvClassify = $(R.id.tv_classify_item);
        }

        @Override
        public void setData(HotShopClassifyModel model) {
            super.setData(model);
            tvClassify.setText(model.getCategoryName());

        }
    }

    public void updateSelectPosition(int position) {
        selectPosition=position;


        notifyDataSetChanged();
    }

}
